package co.edu.aplicacion.persistencia.fwk;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConexionBD {
	
	private static ConexionBD conexion;
	private Connection con;
	
	private ConexionBD(){
		try {
			String url="jdbc:mysql://localhost/reproductor";
			String usuario="root";
			String clave="root";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con= DriverManager.getConnection(url, usuario, clave);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public static ConexionBD getInstance(){
		if(conexion==null){
			conexion=new ConexionBD();
		}
		return conexion;
	}
	
	public void cerrarConexion(){
		try {
			if(con!=null && !con.isClosed()){
				con.close();
			}
			conexion=null;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	public Connection getCon() {
		return con;
	}

	public void setCon(Connection con) {
		this.con = con;
	}
	
	
	

}
